let baseUrl = "http://localhost:8080/netdisc/admin";

function httpGetWithParams(businessUrl, params, callback) {
	let url = baseUrl + businessUrl
	//http请求
	$.ajax({
		type: "get",
		url: url,
		data: params,
		success: function(resp) {
			handlerResp(resp, callback);
		}
	})
}

function httpGet(businessUrl, callback) {
	console.log("httpGet");
	let url = baseUrl + businessUrl;
	//无参数
	$.ajax({
		type: "GET",
		url: url,
		success: function(resp) {
			//http 获得结果
			console.log("===resp===");
			console.log(resp);
			//统一业务处理流程
			handlerResp(resp, callback);
		}
	});
}

function httpPostWithParams(businessUrl, params, callback) {
	let url = baseUrl + businessUrl
	
	$.ajax({
		type: "post",
		url: url,
		data: params,
		xhrFields: {
			withCredentials: true
		},
		contentType: "application/json",
		success: function(resp) {
			handlerResp(resp, callback);
		}
	})
}

function httpPost(businessUrl, callback) {
	let url = baseUrl + businessUrl
	//无参
	$.ajax({
		type: "post",
		url: url,
		success: function(resp) {
			handlerResp(resp, callback);
		}
	})
}

/**
 * 返回结果
 */

function handlerResp(resp, callback) {
	let result = JSON.parse(resp);
    console.log(result);
    //业务状态判断
	if(result.status == 1 || result.status == 2) {
		callback(resp);
	} else {
		//业务处理失败
		alert(result.message)
	}
	
}
